#!/bin/bash
set -e

VERSION=$1
DIR=$2

echo -e "\033[31m ----------------------------------------获取安装包---------------------------------------- \033[0m"
wget https://dl.google.com/go/go${VERSION}.linux-amd64.tar.gz > /dev/null
tar zxf go${VERSION}.linux-amd64.tar.gz -C $DIR 
mkdir $HOME/go

echo -e "\033[31m ----------------------------------------配置环境变量---------------------------------------- \033[0m"
echo "export GOROOT=$DIR/go" >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc
go version

echo -e "\033[31m ----------------------------------------配置golang加速---------------------------------------- \033[0m"
go env -w  GOPROXY=https://goproxy.cn,direct
go env -w GO111MODULE=on
time go get golang.org/x/tour

echo -e "\033[31m ----------------------------------------清理安装目录---------------------------------------- \033[0m"
rm -f go${VERSION}.linux-amd64.tar.gz
